package com.theydream.qeechain.libs;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.theydream.qeechain.R;
import com.theydream.qeechain.ARcaught.ARSphericalView;
import com.theydream.qeechain.globaldata.GlobalData;

public class FourSqareVenue extends ARSphericalView {
	public String name;
	public int checkins;

	// GlobalData.getInstance().getPetList().get(GlobalData.getInstance().getArID()).getPic()
	Drawable drawable = getResources().getDrawable(
			getResources().getIdentifier(
					GlobalData.getInstance().getPetList()
							.get(GlobalData.getInstance().getArID()).getPic(),
					"drawable", "com.theydream.qeechain"));

	public FourSqareVenue(Context ctx) {
		super(ctx);
		inclination = 0;

		// is0 = ctx.getResources().openRawResource(R.drawable.red_bl);
		//
		// mMovie0 = Movie.decodeStream(is0);
		// int w = mMovie0.width();
		// int h = mMovie0.height();
		// mBitmap0 = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
		// mCanvas0 = new Canvas(mBitmap0);

	}

	public void draw(Canvas c, float direction) {

		// p.setColor(Color.RED);
		// p.setTextSize(25);
		Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
		if (name != null) {
			// c.drawText(name, getLeft(), getTop(), p);
			c.drawBitmap(bitmap, getLeft(), getTop(), null);
		}
		// Drawable a1 = getResources().getDrawable(R.drawable.red);
		Drawable b1 = getResources().getDrawable(R.drawable.green);
		// Drawable c1 = getResources().getDrawable(R.drawable.yellow);
		//
		// Bitmap bitmap1 = ((BitmapDrawable) a1).getBitmap();
		Bitmap bitmap2 = ((BitmapDrawable) b1).getBitmap();
		// Bitmap bitmap3 = ((BitmapDrawable) c1).getBitmap();
		// Log.e("TAG", String.valueOf(getLeft()));
		//
		// if (-150 < getLeft() && getLeft() < 450)
		// c.drawBitmap(bitmap2, 450, 20, null);
		// else if (-550 < getLeft() && getLeft() < 850)
		// c.drawBitmap(bitmap3, 450, 20, null);
		// else
		// c.drawBitmap(bitmap1, 450, 20, null);
		Drawable leftArrow = getResources().getDrawable(R.drawable.left_arrow);
		Drawable rightArrow = getResources()
				.getDrawable(R.drawable.right_arrow);
		Bitmap leftArrowBitmap = ((BitmapDrawable) leftArrow).getBitmap();
		Bitmap rightArrowBitmap = ((BitmapDrawable) rightArrow).getBitmap();

		float positiverange = GlobalData.getInstance().getPetDegree() + 150;
		if (positiverange > 360)
			positiverange = positiverange - 360;
		float negativerange = GlobalData.getInstance().getPetDegree() - 150;
		if (negativerange < 0)
			negativerange = negativerange + 360;

		Log.e("TAG",
				"getdegree"
						+ String.valueOf(GlobalData.getInstance()
								.getPetDegree()) + " +"
						+ String.valueOf(positiverange) + " -"
						+ String.valueOf(negativerange));
//		if (direction - 20 < GlobalData.getInstance().getPetDegree()
//				&& GlobalData.getInstance().getPetDegree() < direction + 20)
//			c.drawBitmap(bitmap2, 450, 20, null);

		if (direction - 20 < GlobalData.getInstance().getPetDegree()
				&& GlobalData.getInstance().getPetDegree() < direction + 160)
			c.drawBitmap(rightArrowBitmap, 10, 40, null);

		if (direction - 160 < GlobalData.getInstance().getPetDegree()
				&& GlobalData.getInstance().getPetDegree() < direction + 20)
			c.drawBitmap(leftArrowBitmap, 450, 40, null);


	}
}
